// Fill out your copyright notice in the Description page of Project Settings.


#include "UserWidget/WidgetComponent/SingleQuestCategoryWidget.h"
#include "Components/Border.h"
#include "Components/TextBlock.h"
#include "Components/Button.h"
#include "Libraries/CommonLibrary.h"
#include "Materials/MaterialInstance.h"

#define LOCTEXT_NAMESPACE "BulletScars_Mission"

void USingleQuestCategoryWidget::NativeOnInitialized() {
	Super::NativeOnInitialized();
	CategoryLabel = FText::FromString("ALL");
	Amount = 0.f;
	QuestCategory = EQuestCategoryStatus::All;
	FScriptDelegate Click;
	Click.BindUFunction(this, "ClickEvent");
	FScriptDelegate Hovered;
	Hovered.BindUFunction(this, "HoveredEvent");
	FScriptDelegate UnHovered;
	UnHovered.BindUFunction(this, "UnHoveredEvent");
	AllButton->OnClicked.Add(Click);
	AllButton->OnHovered.Add(Hovered);
	AllButton->OnUnhovered.Add(UnHovered);
}

void USingleQuestCategoryWidget::NativePreConstruct() {
	Super::NativePreConstruct();
	AllText->SetText(FText::Format(LOCTEXT("CategoryAmount", "{0}({1})"), CategoryLabel,FText::AsNumber(Amount)));
	AllIcon->SetBrushFromMaterial(Icon);
	SetUnSelected();
}

void USingleQuestCategoryWidget::UpdateAmount(int32 LAmount) {
	Amount = LAmount;
	AllText->SetText(FText::Format(LOCTEXT("CategoryAmount", "{0}({1})"), CategoryLabel, FText::AsNumber(Amount)));
}

void USingleQuestCategoryWidget::SetUnSelected() {
	AllIcon->SetBrushColor(FLinearColor(1.f, 1.f, 1.f, 0.3f));
	AllText->SetColorAndOpacity(FSlateColor(FLinearColor(1.f, 1.f, 1.f, 0.3f)));
}

void USingleQuestCategoryWidget::SetSelected() {
	AllIcon->SetBrushColor(FLinearColor(1.f, 1.f, 1.f, 1.f));
	AllText->SetColorAndOpacity(FSlateColor(FLinearColor(1.f, 1.f, 1.f, 1.f)));
}

void USingleQuestCategoryWidget::ClickEvent() {
	DEBUG_MESSAGE("ClickEvent");
	QuestCategoryOnClick.Broadcast(this);
}

void USingleQuestCategoryWidget::HoveredEvent() {
	DEBUG_MESSAGE("HoveredEvent");
	QuestCategoryOnHovered.Broadcast(this);
}

void USingleQuestCategoryWidget::UnHoveredEvent() {
	DEBUG_MESSAGE("UnHoveredEvent");
	QuestCategoryOnUnHovered.Broadcast();
}

void USingleQuestCategoryWidget::SimulateClick() {
	QuestCategoryOnClick.Broadcast(this);
}

#undef LOCTEXT_NAMESPACE